/**
 * Created by dqw on 2015/12/30.
 */

//列表开始
var dtGridColumns = [
    {
        id: 'delFlag',
        type: 'int',
        hideQuery:true,
        'export':false,
        hideQueryType:'eq',
        hideQueryValue:1,
        hide:true
    },
    {
        id: 'id',
        title: 'ID',
        type: 'number',
        columnClass: 'text-center width-100',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'eq'
    },
    {
        id: 'userId',
        title: '用户id',
        type: 'string',
        columnClass: 'text-center width-100',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'eq'
    },
    {
        id: 'b.userName',
        title: '用户名',
        type: 'string',
        columnClass: 'text-center width-100',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'b.mobilePhone',
        title: '手机号码',
        type: 'string',
        columnClass: 'text-center width-100',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'operation',
        title: '高手推荐',
        type: 'string',
        columnClass: 'text-center width-200',
        fastSort: false,
        extra: false,
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var html = "",
                publish,
                back;
            if($("#simulationUserPublish") && $("#simulationUserPublish").val() == 1){
                publish = "<a href='javascript:;' class='btn btn-primary btn-sm m-r-10' onclick='OperateHandle.publish(" + record.id + ",\"" + record.highLevel + "\",\"high"+"\")'><i class='fa fa-paper-plane-o'></i>&nbsp;发布&nbsp;</a>";
            }
            if($("#simulationUserBack") && $("#simulationUserBack").val() == 1){
                back = "<a href='javascript:;' class='btn btn-danger btn-sm m-r-10' onclick='OperateHandle.publish(" + record.id+",\"" + record.highLevel + "\",\"high"+"\")'><i class='fa fa-paper-plane-o'></i>&nbsp;撤回&nbsp;</a>";
            }
            if (record.highLevel == 2) {
                html += back ;
            } else if (record.highLevel == 1) {
                html += publish;
            }
            return html;
        }
    },
    {
        id: 'operation',
        title: '最赚钱',
        type: 'string',
        columnClass: 'text-center width-200',
        fastSort: false,
        extra: false,
        resolution: function (value, record) {
            var html = "",
                publish, back;
            if($("#simulationUserPublish") && $("#simulationUserPublish").val() == 1){
                publish = "<a href='javascript:;' class='btn btn-primary btn-sm m-r-10' onclick='OperateHandle.publish(" + record.id + ",\"" + record.mostEarn + "\",\"earn"+"\")'><i class='fa fa-paper-plane-o'></i>&nbsp;发布&nbsp;</a>";
            }
            if($("#simulationUserBack") && $("#simulationUserBack").val() == 1){
                back = "<a href='javascript:;' class='btn btn-danger btn-sm m-r-10' onclick='OperateHandle.publish(" + record.id + ",\"" + record.mostEarn + "\",\"earn"+"\")'><i class='fa fa-paper-plane-o'></i>&nbsp;撤回&nbsp;</a>";
            }
            if (record.mostEarn == 2) {
                html  += back ;
            } else if (record.mostEarn == 1) {
                html += publish;
            }
            return html;
        }
    },
    {
        id: 'operation',
        title: '最稳健',
        type: 'string',
        columnClass: 'text-center width-200',
        fastSort: false,
        extra: false,
        resolution: function (value, record) {
            var html = "",
                publish, back;
            if($("#simulationUserPublish") && $("#simulationUserPublish").val() == 1){
                publish = "<a href='javascript:;' class='btn btn-primary btn-sm m-r-10' onclick='OperateHandle.publish(" + record.id + ",\"" + record.mostSteady + "\",\"steady"+"\")'><i class='fa fa-paper-plane-o'></i>&nbsp;发布&nbsp;</a>";
            }
            if($("#simulationUserBack") && $("#simulationUserBack").val() == 1){
                back = "<a href='javascript:;' class='btn btn-danger btn-sm m-r-10' onclick='OperateHandle.publish(" + record.id + ",\"" + record.mostSteady + "\",\"steady"+"\")'><i class='fa fa-paper-plane-o'></i>&nbsp;撤回&nbsp;</a>";
            }
            if (record.mostSteady == 2) {
                html  += back ;
            } else if (record.mostSteady == 1) {
                html += publish;
            }
            return html;
        }
    },
    {
        id: 'operation',
        title: '最人气',
        type: 'string',
        columnClass: 'text-center width-200',
        fastSort: false,
        extra: false,
        resolution: function (value, record) {
            var html = "",
                publish, back;
            if($("#simulationUserPublish") && $("#simulationUserPublish").val() == 1){
                publish = "<a href='javascript:;' class='btn btn-primary btn-sm m-r-10' onclick='OperateHandle.publish(" + record.id + ",\"" + record.mostPopular + "\",\"popular"+"\")'><i class='fa fa-paper-plane-o'></i>&nbsp;发布&nbsp;</a>";
        }
            if($("#simulationUserBack") && $("#simulationUserBack").val() == 1){
                back = "<a href='javascript:;' class='btn btn-danger btn-sm m-r-10' onclick='OperateHandle.publish(" + record.id + ",\"" + record.mostPopular + "\",\"popular"+"\")'><i class='fa fa-paper-plane-o'></i>&nbsp;撤回&nbsp;</a>";
            }
            if (record.mostPopular == 2) {
                html  += back ;
            } else if (record.mostPopular == 1) {
                html += publish;
            }
            return html;
        }
    }
];

var dtGridOption = {
    lang: 'zh-cn',
    ajaxLoad: true,
    loadURL: ncGlobal.adminRoot + 'simulation/user/json/list',
    exportFileName: '模拟用户',
    columns: dtGridColumns,
    gridContainer: 'dtGridContainer',
    toolbarContainer: 'dtGridToolBarContainer',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50],
    ncColumnsType: {int: ["id","userId"]}
};

var grid = $.fn.DtGrid.init(dtGridOption);
grid.fastQueryParameters = new Object();

//排序
grid.sortParameter.columnId = ['asc_id'];
grid.fastQueryParameters['eq_delFlag'] = 1;
grid.sortParameter.sortType = 1;

//操作处理开始
var OperateHandle = function () {

    function _bindEvent() {
        //模糊搜索
        $('#customSearch').click(function () {
            grid.fastQueryParameters = new Object();
            grid.fastQueryParameters['eq_delFlag'] = 1;
            grid.fastQueryParameters['lk_real_name'] = $('#keyword').val();
            grid.pager.startRecord = 0;
            grid.pager.nowPage = 1;
            grid.pager.recordCount = -1;
            grid.pager.pageCount = -1;
            grid.refresh(true);
        });
    }
    /**
     * 推荐发布
     */
    function _pubInfo(id, status,mark) {
        var tpl = '您是否确定此操作？'
        $.ncConfirm({
            url: ncGlobal.adminRoot + "simulation/json/pubInfo",
            data: {
                id: id,
                status:status,
                mark:mark
            },
            content: tpl,
            alertTitle: "操作"
        });
    }

    //外部可调用
    return {
        bindEvent: _bindEvent,
        publish: _pubInfo
    }
}();
//操作处理结束

$(function () {
    //加载列表
    grid.load();
    //页面绑定事件
    OperateHandle.bindEvent();
});